<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000">
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top">
  
  
  <title>02-深圳市南山区-同行者科技有限公司面试总结 | 山岚 - 90码农历险记</title>
  <meta name="description" content="基本信息时间：2019年7月19日10点30 地点：深圳市南山区高新南七道国家高新技术产业创新中心A座1301；这个A座地图上看不见，最后问保安才知道的，出门在外说话多讲礼貌，多问路，能节省很多麻烦。缺点就是离距离地铁站很远1.3公里，步行要十几分钟，这个天气非常热（深圳好像就没有不热的时候） 公司：深圳市同行者科技有限公司 职位：语音开发工程师 环境：环境很不错，所处的是高新技术产业园，所以在这">
<meta name="keywords" content="Java面试题">
<meta property="og:type" content="article">
<meta property="og:title" content="02-深圳市南山区-同行者科技有限公司面试总结">
<meta property="og:url" content="https://blog.gobyte.cn/post/8905a03f.html">
<meta property="og:site_name" content="山岚博客">
<meta property="og:description" content="基本信息时间：2019年7月19日10点30 地点：深圳市南山区高新南七道国家高新技术产业创新中心A座1301；这个A座地图上看不见，最后问保安才知道的，出门在外说话多讲礼貌，多问路，能节省很多麻烦。缺点就是离距离地铁站很远1.3公里，步行要十几分钟，这个天气非常热（深圳好像就没有不热的时候） 公司：深圳市同行者科技有限公司 职位：语音开发工程师 环境：环境很不错，所处的是高新技术产业园，所以在这">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://ws3.sinaimg.cn/large/96e311f0gy1g55ft2pae7j20ep0f3ajk.jpg">
<meta property="og:updated_time" content="2019-12-10T08:14:59.804Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="02-深圳市南山区-同行者科技有限公司面试总结">
<meta name="twitter:description" content="基本信息时间：2019年7月19日10点30 地点：深圳市南山区高新南七道国家高新技术产业创新中心A座1301；这个A座地图上看不见，最后问保安才知道的，出门在外说话多讲礼貌，多问路，能节省很多麻烦。缺点就是离距离地铁站很远1.3公里，步行要十几分钟，这个天气非常热（深圳好像就没有不热的时候） 公司：深圳市同行者科技有限公司 职位：语音开发工程师 环境：环境很不错，所处的是高新技术产业园，所以在这">
<meta name="twitter:image" content="https://ws3.sinaimg.cn/large/96e311f0gy1g55ft2pae7j20ep0f3ajk.jpg">
  <!-- Canonical links -->
  <link rel="canonical" href="https://blog.gobyte.cn/post/8905a03f.html">
  
    <link rel="alternate" href="/atom.xml" title="山岚博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/shan-2.png" type="image/x-icon">
  
  <link rel="stylesheet" href="/css/style.css">
  
  
  
  
</head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/shanlanCoding" target="_blank">
          <img class="img-circle img-rotate" src="/images/ha-002-small.png" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">山岚</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">半吊子全栈开发者</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Work in 0755; Home is in 0713</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/links/">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/shanlanCoding" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=CWRgen1se2phZnxJeHgnamZk" target="_blank" title="Email" data-toggle=tooltip data-placement=top><i class="icon icon-email"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验，知无不言言无不尽!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/windows/">windows</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/前端/">前端</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/博客优化/">博客优化</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/变得更好/">变得更好</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/心情/">心情</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/手机/">手机</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/服务器/">服务器</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/求职/">求职</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/骚操作/">骚操作</a><span class="category-list-count">3</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/AutoJs/">AutoJs</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Hexo/">Hexo</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/">Java</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java面试题/">Java面试题</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React/">React</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React教程/">React教程</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/centOS/">centOS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java基础/">java基础</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java集合框架/">java集合框架</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/">vue</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/windows-10/">windows 10</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/人脸识别/">人脸识别</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/博客优化/">博客优化</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/吐槽/">吐槽</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/小米6/">小米6</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/思维改变/">思维改变</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/自定义手机号/">自定义手机号</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/tags/AutoJs/" style="font-size: 13.2px;">AutoJs</a> <a href="/tags/Git/" style="font-size: 13.4px;">Git</a> <a href="/tags/Hexo/" style="font-size: 13.8px;">Hexo</a> <a href="/tags/Java/" style="font-size: 13px;">Java</a> <a href="/tags/JavaScript/" style="font-size: 13.2px;">JavaScript</a> <a href="/tags/Java面试题/" style="font-size: 13.6px;">Java面试题</a> <a href="/tags/React/" style="font-size: 14px;">React</a> <a href="/tags/React教程/" style="font-size: 13px;">React教程</a> <a href="/tags/centOS/" style="font-size: 13px;">centOS</a> <a href="/tags/java基础/" style="font-size: 13px;">java基础</a> <a href="/tags/java集合框架/" style="font-size: 13px;">java集合框架</a> <a href="/tags/linux/" style="font-size: 13px;">linux</a> <a href="/tags/nginx/" style="font-size: 13.2px;">nginx</a> <a href="/tags/vue/" style="font-size: 13px;">vue</a> <a href="/tags/windows-10/" style="font-size: 13px;">windows 10</a> <a href="/tags/人脸识别/" style="font-size: 13px;">人脸识别</a> <a href="/tags/博客优化/" style="font-size: 13px;">博客优化</a> <a href="/tags/吐槽/" style="font-size: 13px;">吐槽</a> <a href="/tags/小米6/" style="font-size: 13px;">小米6</a> <a href="/tags/思维改变/" style="font-size: 13px;">思维改变</a> <a href="/tags/自定义手机号/" style="font-size: 13px;">自定义手机号</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">十二月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">十一月 2019</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">十月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">九月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">八月 2019</a><span class="archive-list-count">11</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">七月 2019</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">六月 2019</a><span class="archive-list-count">9</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/前端/">前端</a>
              </p>
              <p class="item-title">
                <a href="/post/7080982b.html" class="title">AntD的一个警告解决方法：defaultvalue is invalid for getfielddecorator will set value please use option.initialvalue instead</a>
              </p>
              <p class="item-date">
                <time datetime="2019-12-07T08:58:03.000Z" itemprop="datePublished">2019-12-07</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/JavaScript/">JavaScript</a>
              </p>
              <p class="item-title">
                <a href="/post/cbc43a97.html" class="title">海信A5自动阅读打卡签到工具软件脚本</a>
              </p>
              <p class="item-date">
                <time datetime="2019-12-06T09:03:39.000Z" itemprop="datePublished">2019-12-06</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/JavaScript/">JavaScript</a>
              </p>
              <p class="item-title">
                <a href="/post/ae3d322e.html" class="title"> AutoJs获取的Text文本是乱码|Android爬虫反字体屏蔽乱码解决方案 </a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-23T03:50:19.000Z" itemprop="datePublished">2019-11-23</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/服务器/">服务器</a>
              </p>
              <p class="item-title">
                <a href="/post/1a22163b.html" class="title">GitHub克隆clone太慢添加代理加速访问</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-13T03:51:13.000Z" itemprop="datePublished">2019-11-13</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/心情/">心情</a>
              </p>
              <p class="item-title">
                <a href="/post/d90e4430.html" class="title">奇葩公司每周晚上占用下班时间开会、团建（跑步）</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-11T06:36:16.000Z" itemprop="datePublished">2019-11-11</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#基本信息"><span class="toc-number">1.</span> <span class="toc-text">基本信息</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#面试题"><span class="toc-number">2.</span> <span class="toc-text">面试题</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#1-不使用语言的分割组合函数（如Java的String-split，php的explode和implode）。"><span class="toc-number">3.</span> <span class="toc-text">1. 不使用语言的分割组合函数（如Java的String.split，php的explode和implode）。</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-1字符串按分割串拆分成数组"><span class="toc-number">3.1.</span> <span class="toc-text">1.1字符串按分割串拆分成数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-2实现字符串列表按分割串组合，例如数组：-“ab”-”2”-，通过”-amp-amp-”分隔符，组成新的字符串“ab-amp-amp-2”"><span class="toc-number">3.2.</span> <span class="toc-text">1.2实现字符串列表按分割串组合，例如数组：[“ab”,”2”]，通过”&amp;&amp;”分隔符，组成新的字符串“ab&amp;&amp;2”</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-找出不大于N的最大质数"><span class="toc-number">4.</span> <span class="toc-text">2. 找出不大于N的最大质数</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#基础版："><span class="toc-number">4.1.</span> <span class="toc-text">基础版：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#进阶版："><span class="toc-number">4.2.</span> <span class="toc-text">进阶版：</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-1000个数的范围是-0-999-，有两个相同的数，请设计算法找出来"><span class="toc-number">5.</span> <span class="toc-text">3. 1000个数的范围是[0,999]，有两个相同的数，请设计算法找出来</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-n个人（编号1-n-）-围成一圈从编号1开始报数，从1报到m，报到m的人出来，下一个人继续从1开始报数。编程求最后一个留下的人的编号。"><span class="toc-number">6.</span> <span class="toc-text">4. n个人（编号1 ~ n ） 围成一圈从编号1开始报数，从1报到m，报到m的人出来，下一个人继续从1开始报数。编程求最后一个留下的人的编号。</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-使用数组和for循环来解题"><span class="toc-number">6.1.</span> <span class="toc-text">1. 使用数组和for循环来解题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-面向对象解题思路"><span class="toc-number">6.2.</span> <span class="toc-text">2. 面向对象解题思路</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-使用链表来解题"><span class="toc-number">6.3.</span> <span class="toc-text">3. 使用链表来解题</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5-26个字母a-z，找出所有字母的组合，a-b-c-ab-abc-a-z都是一个组合（顺序无关）"><span class="toc-number">7.</span> <span class="toc-text">5. 26个字母a-z，找出所有字母的组合，a,b,c,ab,abc,a~z都是一个组合（顺序无关）</span></a></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-02-深圳市同行者科技有限公司面试总结" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header" name="标题头部>
      
        
  
    <h1 class="article-title" itemprop="name">
      02-深圳市南山区-同行者科技有限公司面试总结
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/post/8905a03f.html" class="article-date">
	  <time datetime="2019-07-19T12:27:19.000Z" itemprop="datePublished">2019-07-19</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/categories/求职/">求职</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/tags/Java面试题/">Java面试题</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


	<span class="article-read hidden-xs">
    	<i class="icon icon-eye-fill" aria-hidden="true"></i>
    	<span id="/post/8905a03f.html" class="leancloud_visitors"  data-flag-title="02-深圳市南山区-同行者科技有限公司面试总结">
			<span class="leancloud-visitors-count">0</span>
		</span>
    </span>

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/post/8905a03f.html#comments" class="article-comment-link">评论</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody" name="正文">
      
        <h1 id="基本信息"><a href="#基本信息" class="headerlink" title="基本信息"></a>基本信息</h1><p>时间：2019年7月19日10点30</p>
<p>地点：深圳市南山区高新南七道国家高新技术产业创新中心A座1301；这个A座地图上看不见，最后问保安才知道的，出门在外说话多讲礼貌，多问路，能节省很多麻烦。缺点就是离距离地铁站很远1.3公里，步行要十几分钟，这个天气非常热（深圳好像就没有不热的时候）</p>
<p>公司：深圳市同行者科技有限公司</p>
<p>职位：语音开发工程师</p>
<p>环境：环境很不错，所处的是高新技术产业园，所以在这附近的都是科技、电子行业，比如我就看到了创维的牌子。进了大厦还需要登记，否则你没办法过闸机的。登记的时候也没有怎么为难，基本是留个名字和手机号，身份证号和手机号是可选的，这个是在别的公司见不到的情况。</p>
<p>流程：给HR看简历，可能是根据简历给你发试卷和基本信息调查表。注明试卷和答案纸是分开的，不是直接填在试卷上。与第一家公司“中科软科技股份有限公司”不同的是，这家公司没有让我填杂七杂八的信息调查表，这样以后个人信息泄露的风险就降低了，点个赞。</p>
<h1 id="面试题"><a href="#面试题" class="headerlink" title="面试题"></a>面试题</h1><p>面试题我拍了照，我直接上照片：</p>
<p><img src="//ws3.sinaimg.cn/large/96e311f0gy1g55ft2pae7j20ep0f3ajk.jpg" alt="深圳市同行者科技有限公司"></p>
<p>在我面试之前已经有两个老哥在做题了，他俩都是面试Java的。一个老哥说自己有点工作经验；另一个老哥说应届，6月底才来深圳，已经面了7/8家了，但是还没有拿到offer，做题的时候发现他跟我差不多，写不出几题，同是天涯沦落人，哈哈哈，话不多数直接上真题和正确答案。</p>
<h1 id="1-不使用语言的分割组合函数（如Java的String-split，php的explode和implode）。"><a href="#1-不使用语言的分割组合函数（如Java的String-split，php的explode和implode）。" class="headerlink" title="1. 不使用语言的分割组合函数（如Java的String.split，php的explode和implode）。"></a>1. 不使用语言的分割组合函数（如Java的String.split，php的explode和implode）。</h1><h2 id="1-1字符串按分割串拆分成数组"><a href="#1-1字符串按分割串拆分成数组" class="headerlink" title="1.1字符串按分割串拆分成数组"></a>1.1字符串按分割串拆分成数组</h2><p>代码思路：</p>
<ol>
<li>利用String的container方法，判断是否包含分隔符号flag</li>
<li>若包含，则使用indexOf返回分隔符的下标值</li>
<li>使用String.substring来截取字符串。substring一共有有两种用法，这里使用第二中，也就是从0截取到flag<ol>
<li><code>str.substring(beginIndex) ;</code>从index向后截取所有字符串，包含beginIndex</li>
<li><code>str.substring(beginIndex, endindex);</code> 向后截取字符串，一直到endIndex。含beginIndex，不含endIndex</li>
</ol>
</li>
<li>把步骤3截取到干净的字符串，添加到数组集合里</li>
<li>截取新的str，由于步骤4已经截取了第一个字符串，所以新的str也需要重新截取。方法是利用步骤3的第一种方法。具体代码是：<code>str.substring(index + flag.length() )</code>。原理是：从flag开始截取，但是不包含flag，所以需要加上flag的长度，也就是<code>flag.length()</code>，最后如此循环即可完成截取。</li>
</ol>
<details><summary>点击查看完整代码</summary>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * TOO: 分割字符串返回ArrayList</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@author</span> shanLan misterchou@qq.com</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@date</span> 2019/7/19 22:02</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * 测试字符串 ： String str = "asf,123,dsaf,dgasd123,asdfa1,asdfs34,dfas23.-";</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> String[] mySplict(String str, String flag) &#123;</span><br><span class="line">        ArrayList&lt;String&gt; al = <span class="keyword">new</span> ArrayList&lt;String&gt;();</span><br><span class="line">        <span class="keyword">while</span> (str.contains(flag)) &#123;</span><br><span class="line">            <span class="comment">// 返回标记的下标</span></span><br><span class="line">            <span class="keyword">int</span> index = str.indexOf(flag);</span><br><span class="line">            <span class="comment">// 把截取好的字符串存起来</span></span><br><span class="line">            String tmp = str.substring(<span class="number">0</span>, index);</span><br><span class="line">            al.add(tmp);</span><br><span class="line">            str = str.substring(index + flag.length());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 兜底；若字符串里不包含flag，说明这个字符串不需要切割，那么字节添加到ArrayList里</span></span><br><span class="line">        al.add(str);</span><br><span class="line">        <span class="comment">// 通过toArray方法，指定数组类型直接转换。</span></span><br><span class="line">        <span class="keyword">return</span> al.toArray(<span class="keyword">new</span> String[al.size()]);</span><br><span class="line">    &#125;</span><br><span class="line"><span class="comment">// ------打印结果------</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">asf</span></span><br><span class="line"><span class="comment">123</span></span><br><span class="line"><span class="comment">dsaf</span></span><br><span class="line"><span class="comment">dgasd123</span></span><br><span class="line"><span class="comment">asdfa1</span></span><br><span class="line"><span class="comment">asdfs34</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>

</details>



<h2 id="1-2实现字符串列表按分割串组合，例如数组：-“ab”-”2”-，通过”-amp-amp-”分隔符，组成新的字符串“ab-amp-amp-2”"><a href="#1-2实现字符串列表按分割串组合，例如数组：-“ab”-”2”-，通过”-amp-amp-”分隔符，组成新的字符串“ab-amp-amp-2”" class="headerlink" title="1.2实现字符串列表按分割串组合，例如数组：[“ab”,”2”]，通过”&amp;&amp;”分隔符，组成新的字符串“ab&amp;&amp;2”"></a>1.2实现字符串列表按分割串组合，例如数组：[“ab”,”2”]，通过”&amp;&amp;”分隔符，组成新的字符串“ab&amp;&amp;2”</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">mySplict2</span><span class="params">(String[] str, String flag)</span> </span>&#123;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">         * 1.先遍历数组，取出每个元素</span></span><br><span class="line"><span class="comment">         * 2.判断元素是否为最后一位，若是，则不再加分隔符</span></span><br><span class="line"><span class="comment">         * */</span></span><br><span class="line">    StringBuilder sb = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; str.length; i++) &#123;</span><br><span class="line">        sb.append(str[i]);</span><br><span class="line">        <span class="keyword">if</span> (i &lt; str.length - <span class="number">1</span> ) &#123;</span><br><span class="line">            sb.append(flag);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> sb.toString();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="2-找出不大于N的最大质数"><a href="#2-找出不大于N的最大质数" class="headerlink" title="2. 找出不大于N的最大质数"></a>2. 找出不大于N的最大质数</h1><p><strong>质数和素数是同一个东西</strong>。质数（又称素数），是指在大于1的自然数中，除了1和它本身外，不能被<strong>其他自然数整除</strong>（除0以外）的数称之为素数（质数）。比1大但不是素数的数称为<strong>合数</strong>，1和0既非素数也非合数。<br>素数不是奇数。奇数是不能被2整除的数。比如9是奇数，但不是素数。因为9不能被2整除，所以是奇数，但9有1、3、9三个因数，所以不是素数。</p>
<p>在计算机中，计算整除的常用方法一般使用<code>% 运算</code>，读作取模运算，用法：7 %  2 = 1 。解释： 7 模以 2 ，商为3，余数为1，这就称之为取模。我目前对取模运算的理解是求余数，更加常见的应用场景：</p>
<blockquote>
<ol>
<li>判别奇偶数</li>
<li>判别素数</li>
<li>求最大公约数</li>
<li>水仙花数</li>
<li>模幂运算</li>
<li>《孙子问题(中国剩余定理)》</li>
<li>凯撒密码</li>
</ol>
</blockquote>
<p>本题是使用<strong>取模运算</strong>来判别质数，也就是素数。为了便于理解，先列出判别素数的基本思路：</p>
<h2 id="基础版："><a href="#基础版：" class="headerlink" title="基础版："></a>基础版：</h2><ol>
<li>定义循环，数字 i = n ，还要定义数字 j = i - 1，都为自减。且 i 和 j 都要大于 1 （因为质数大于1）</li>
<li>使用取模运算，每个循环 i % j ，并且判断取模结果是否为 0 ，若为 0 则说明该数字不是一个素数，使用break跳出循环，并进行自减，一直到 j  &gt;= 2 时，若还没有跳出循环，那么此时的 i 肯定是一个质数了。因为质数的定义是不包括被1和自身的整除的数。而 j &gt;= 2时，说明 j 到 2之间所有的数字已经遍历完成，这时还没有跳出循环就说明 i 已经符合质数了。</li>
<li>将符合的数字存入到ArrayList中，利用List集合的顺序存入特性，由于是自减循环，所以第一个存入的质数自然为最大的</li>
<li>最后使用ArrayList.get(0)取出第一个下标的数，即为不大于N的最大质数<details><summary>点击查看完整代码</summary>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">TODO:</span> 求不大于N的最大质数</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> shanLan misterchou@qq.com</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2019/7/24 0:49</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">maxPrimeNum</span><span class="params">(<span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">    <span class="comment">// 用来存质数</span></span><br><span class="line">    ArrayList&lt;Integer&gt; arr = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">    <span class="keyword">if</span> (n == <span class="number">2</span> || n == <span class="number">1</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> n;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = n - <span class="number">1</span>; i &gt; <span class="number">1</span>; i--) &#123;</span><br><span class="line">        <span class="comment">// 比i小1的数</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = i - <span class="number">1</span>; j &gt; <span class="number">1</span>; j--) &#123;</span><br><span class="line">            <span class="comment">// 非质数</span></span><br><span class="line">            <span class="keyword">if</span> (i % j == <span class="number">0</span>) &#123;</span><br><span class="line">                <span class="keyword">break</span>;<span class="comment">//跳出冫</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 只有j小于等于2，并且没有break跳出循环时，此时的i才为质数</span></span><br><span class="line">            <span class="keyword">if</span> (j &lt;= <span class="number">2</span>) &#123;</span><br><span class="line">                <span class="comment">// 存入集合中，便于后续取出</span></span><br><span class="line">                arr.add(i);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 利用ArrayList顺序存储的特性，将第一个存入的数字取出。</span></span><br><span class="line">    <span class="comment">// 原因是我们采用自减遍历，所以第一个遍历出来的质数是最大的</span></span><br><span class="line">    System.err.println(<span class="string">"不大于"</span> + n + <span class="string">"的最大质数="</span> + arr.get(<span class="number">0</span>));</span><br><span class="line">    <span class="keyword">return</span> arr.get(<span class="number">0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</details></li>
</ol>


<h2 id="进阶版："><a href="#进阶版：" class="headerlink" title="进阶版："></a>进阶版：</h2><p>利用开平方根，来缩数字的范围，从而提高查找的效率。</p>
<p>原理：因为如果它不是质数，那么它一定可以表示成除了<strong>1和它本身</strong>之外的两个数相乘，这两个数必然有一个小于等于它的平方根。只要找到小于或等于的那个就行了</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1000</span>; i &gt; <span class="number">2</span>; i--) &#123;</span><br><span class="line">        <span class="keyword">if</span> (m(i)) &#123;</span><br><span class="line">            System.err.println(<span class="string">"N内最大的质数："</span> + i);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span>  <span class="title">m</span><span class="params">(<span class="keyword">int</span> num)</span></span>&#123;</span><br><span class="line">    <span class="comment">// 利用JDK的Math的开平方函数，来限定J的范围</span></span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">2</span>; j&lt;=Math.sqrt(num);j++)&#123;</span><br><span class="line">        <span class="keyword">if</span>( num % j == <span class="number">0</span> )&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="3-1000个数的范围是-0-999-，有两个相同的数，请设计算法找出来"><a href="#3-1000个数的范围是-0-999-，有两个相同的数，请设计算法找出来" class="headerlink" title="3. 1000个数的范围是[0,999]，有两个相同的数，请设计算法找出来"></a>3. 1000个数的范围是[0,999]，有两个相同的数，请设计算法找出来</h1><p>既然不限定语言，我一开始想最简单的方法就是利用Java集合Set的特性来完成，事实上这种方法代码量也是最少。这里再来复习下<strong>Set的特性：存取无序；不可重复；没有下标。</strong><a href="https://blog.gobyte.cn/post/57eede11.html#HashSet">更详细点击这里</a></p>
<p>HashSet它的Add()添加元素的时候，会有一个Boolean的返回值。若集合中没有找到存在的元素，则可以存入并且返回True，否则返回False，所以利用该特性直接就能判断哪个元素重复了，下面上示例代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">    <span class="comment">// 构造一个包含1000个数字的空数组</span></span><br><span class="line">    <span class="keyword">int</span> arr[] = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">1000</span>];</span><br><span class="line">    <span class="comment">// 给数组赋值</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">999</span>; i++) &#123;</span><br><span class="line">        arr[i] = i;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 添加一个重复的数字</span></span><br><span class="line">    arr[<span class="number">999</span>] = <span class="number">888</span>;</span><br><span class="line">    System.err.println(isEquals(arr));</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">isEquals</span><span class="params">(<span class="keyword">int</span>[] i)</span> </span>&#123;</span><br><span class="line">    HashSet&lt;Integer&gt; hashSet = <span class="keyword">new</span> HashSet&lt;&gt;();</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; i.length; j++) &#123;</span><br><span class="line">        <span class="comment">// 当添加元素返回True时不进入if</span></span><br><span class="line">        <span class="keyword">if</span> ( !( hashSet.add( i[j] )) ) &#123;</span><br><span class="line">            <span class="keyword">return</span> i[j];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> -<span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="4-n个人（编号1-n-）-围成一圈从编号1开始报数，从1报到m，报到m的人出来，下一个人继续从1开始报数。编程求最后一个留下的人的编号。"><a href="#4-n个人（编号1-n-）-围成一圈从编号1开始报数，从1报到m，报到m的人出来，下一个人继续从1开始报数。编程求最后一个留下的人的编号。" class="headerlink" title="4. n个人（编号1 ~ n ） 围成一圈从编号1开始报数，从1报到m，报到m的人出来，下一个人继续从1开始报数。编程求最后一个留下的人的编号。"></a>4. n个人（编号1 ~ n ） 围成一圈从编号1开始报数，从1报到m，报到m的人出来，下一个人继续从1开始报数。编程求最后一个留下的人的编号。</h1><blockquote>
<p>例如：</p>
<p>如人数n=3,报数 m=4<br>第一次出队：1<br>第二次出队：3<br>最后留下： 2</p>
</blockquote>
<h2 id="1-使用数组和for循环来解题"><a href="#1-使用数组和for循环来解题" class="headerlink" title="1. 使用数组和for循环来解题"></a>1. 使用数组和for循环来解题</h2><ol>
<li><p>创建一个数组<code>peopleFags[]</code>，数组长度为总人数，数组的每个元素下标代表每个人，数组的内容表示这个人是否被淘汰。true没有淘汰，false表示已经淘汰</p>
</li>
<li><p>最开始的时候所有人都没有淘汰，所以这个数组应该全部赋值为true</p>
</li>
<li><p>数数是从第一个人开始，所以需要定义一个变量count，初始值为0，代表第一个人</p>
</li>
<li><p>既然是数数，那么肯定要有一个变量记录已经数到了哪个人，所以定义变量index，一开始都是从第一个人开始数数，所以初始值也是0</p>
</li>
<li><p>还需要定义一个变量，记录剩余的人数，peopleResidue，一开始没有人淘汰，所以它等于总人数</p>
</li>
<li><p>所有变量定义完成之后，开始循环处理，循环的条件是总人数不小于1，也就是总人数：total &gt; 1为条件</p>
</li>
<li><p>进入循环后应该判断当前的人<code>peopleFags[index]</code>是不是淘汰了，如没有淘汰，则应该把计数器count++自增一次，随后应该判断count计数器是不是等于报数，因为游戏规则表名等于报数的人要被淘汰，所以当count等于报数时，应该将当前的人赋值为false，既然已经淘汰了，所以要归零。随之还要将剩余人数减1</p>
</li>
<li><p>最后让当前index下标递进一位，并判断index是否等于总人数，如果等于总人数则表示这一轮数完了，所以应该归零重新开始计数</p>
</li>
<li><p>循环结束后遍历<code>peopleFags[]</code>数组，把为true的下标加1，就是最后一个人的编号。</p>
<p><strong>下面是示例代码：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> compult = compult(<span class="number">9</span>, <span class="number">10</span>);</span><br><span class="line">    <span class="keyword">if</span> (compult != -<span class="number">1</span>) &#123;</span><br><span class="line">        System.err.println(<span class="string">"最后留下来的人是："</span> + compult);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">TODO:</span> 计算循环</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> total     总人数</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> keyNumber 报数</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> int: 最后一个人的编号负</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> shanLan misterchou@qq.com</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2019/7/28 23:33</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">compult</span><span class="params">(<span class="keyword">int</span> total, <span class="keyword">int</span> keyNumber)</span> </span>&#123;</span><br><span class="line">    <span class="comment">// 长度为total的布尔型数组，该数组的长度为总人数，下标索引表示哪个人，元素内容True表示未淘汰，False淘汰</span></span><br><span class="line">    <span class="keyword">boolean</span>[] peopleFlags = <span class="keyword">new</span> <span class="keyword">boolean</span>[total];</span><br><span class="line">    <span class="comment">// 初始化peopleFlags数组，因为一开始所有人都没有淘汰，自然赋值为true</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; peopleFlags.length; i++) &#123;</span><br><span class="line">        peopleFlags[i] = <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 剩余的人数，一开始没有人被淘汰，所以剩余人数是总人数total</span></span><br><span class="line">    <span class="keyword">int</span> peopleResidue = total;</span><br><span class="line">    <span class="comment">// 计数器；初始值0，每数一个人则加1，当等于总人数total时归零</span></span><br><span class="line">    <span class="keyword">int</span> count = <span class="number">0</span>;</span><br><span class="line">    <span class="comment">// 当前数到哪个人，从0开始计数，代表第一个人</span></span><br><span class="line">    <span class="keyword">int</span> index = <span class="number">0</span>;</span><br><span class="line">    <span class="comment">// 开始循环，当剩余人数小于等于1，则说明已经是最后一个人，不进入循环</span></span><br><span class="line">    <span class="comment">// 否则应该不累加计数器，所以跳过。</span></span><br><span class="line">    <span class="keyword">while</span> (peopleResidue &gt; <span class="number">1</span>) &#123;</span><br><span class="line">        <span class="comment">// 进入循环后，判断当前的人的peopleFlags[index]是不是true</span></span><br><span class="line">        <span class="keyword">if</span> (peopleFlags[index]) &#123;</span><br><span class="line">            <span class="comment">// 能进入循环，说明还没有淘汰，所以要累加计数器</span></span><br><span class="line">            count++;</span><br><span class="line">            <span class="comment">// 检查下计数器count，如果等于报数keyNumber，应该归零，因为等于报数的人应该被淘汰出去</span></span><br><span class="line">            <span class="keyword">if</span> (count == keyNumber) &#123;</span><br><span class="line">                count = <span class="number">0</span>;</span><br><span class="line">                <span class="comment">// 既然被淘汰，那么他的peopleFlags[index]应该赋值false</span></span><br><span class="line">                peopleFlags[index] = <span class="keyword">false</span>;</span><br><span class="line">                <span class="comment">// 既然已经淘汰了一个人，那么剩余的总人数应该-1，也就是peopleResidue - 1</span></span><br><span class="line">                peopleResidue--;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 当前人index的下标递进一位</span></span><br><span class="line">        index++;</span><br><span class="line">        <span class="comment">//判断当前人index下标是不是等于总人数total，如果等于则说明这一轮循环结束了，所以要归零从0开始继续循环</span></span><br><span class="line">        <span class="keyword">if</span> (index == total) &#123;</span><br><span class="line">            index = <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// while循环结束后，剩余的人数是1，被淘汰的已经标记为false，现在要做的是把没有被淘汰的元素peopleFlags[index] = true 的人下标 + 1</span></span><br><span class="line">    <span class="comment">// 因为在人类中计数是从1开始，而我们写的程序的计数是从0开始，所以要加1</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; total; i++) &#123;</span><br><span class="line">        <span class="keyword">if</span> (peopleFlags[i]) &#123;</span><br><span class="line">            <span class="comment">// 返回没有被剔除的人</span></span><br><span class="line">            <span class="keyword">return</span> i + <span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> -<span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h2 id="2-面向对象解题思路"><a href="#2-面向对象解题思路" class="headerlink" title="2. 面向对象解题思路"></a>2. 面向对象解题思路</h2><p>本题中有两个对象，一个是人People，还有一个是环Circle。</p>
<p>人：</p>
<ul>
<li>编号</li>
<li>左边的People</li>
<li>右边的People</li>
</ul>
<p>环：</p>
<ul>
<li>总人数</li>
<li>第一个人</li>
<li>最后一个人</li>
<li>添加人()</li>
<li>删除人()</li>
</ul>
<p>一开始，我们的环是空的，所以我们需要往环里添加人。那么人肯定有编号，所以添加人之前要给人加上编号。 </p>
<p>接下来我们要创建一个计数器变量count，初始值为0，它主要是记录我们循环了几次，每循环一次等于数了一个人。当计数器count等于报数keyNumber的时候，说明这个人就需要被淘汰了，具体请看下面<code>环Circle</code>对象的代码：</p>
<details><summary>点击查看-环Circle-代码</summary>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> pojo;</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">circle</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> total = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">private</span> people fristPeople = <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">private</span> people lastPeople = <span class="keyword">null</span>;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">TODO:</span> 添加一个人到圈里</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> newPeople 新添加的人</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> void:</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@author</span> shanLan misterchou@qq.com</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@date</span> 2019/7/31 0:45</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addPeople</span><span class="params">(people newPeople)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// 当圈里面的总人数为0</span></span><br><span class="line">        <span class="keyword">if</span> (total &lt;= <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="comment">// 因为圈里没人时，那么刚添加的这个人的是第一个人，也是最后一个人</span></span><br><span class="line">            fristPeople = newPeople;</span><br><span class="line">            lastPeople = newPeople;</span><br><span class="line">            <span class="comment">// 同理，所以这个人的左边、右边，都是这个人。</span></span><br><span class="line">            newPeople.setLeftPeople(newPeople);</span><br><span class="line">            newPeople.setRightPeole(newPeople);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// 如果圈里有人，则把该人加到圈的尾部,也就是将之前最后最后一个人的右边设置为新人。例如：现在新人是编号4</span></span><br><span class="line">            <span class="comment">// 1 -&gt; 2 -&gt; 3 -&gt; 4    人员顺序示意</span></span><br><span class="line">            lastPeople.setRightPeole(newPeople);</span><br><span class="line">            <span class="comment">// 将新人4的左边设置为之前最后那个人，也就是编号3</span></span><br><span class="line">            newPeople.setLeftPeople(lastPeople);</span><br><span class="line">            <span class="comment">// 将新人的右边，设置为第一个人，也就是编号1</span></span><br><span class="line">            newPeople.setRightPeole(fristPeople);</span><br><span class="line">            <span class="comment">// 把最后一个人设置为新人</span></span><br><span class="line">            lastPeople = newPeople;</span><br><span class="line">        &#125;</span><br><span class="line">        total++;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">TODO:</span> 删除圈里的人</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> p 被删除的人</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> void:</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@author</span> shanLan misterchou@qq.com</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@date</span> 2019/7/31 0:58</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">deletPeople</span><span class="params">(people p)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (total &lt;= <span class="number">0</span>) &#123;</span><br><span class="line">            System.err.println(<span class="string">"圈里总人数小于等于0 ，不能删除！"</span>);</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (total == <span class="number">1</span>) &#123;</span><br><span class="line">            <span class="comment">// 当圈里只有一个人，此时应该游戏结束，第一个人和最后一个人都是null</span></span><br><span class="line">            fristPeople = lastPeople = <span class="keyword">null</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// 1 -&gt; 2 -&gt; 3 -&gt; 4    人员顺序示意</span></span><br><span class="line">            <span class="comment">// 当圈中的人不小于等于0、且大于1则开始正常操作</span></span><br><span class="line">            <span class="keyword">if</span> (p == fristPeople) &#123;</span><br><span class="line">                <span class="comment">// 如果新人等于第一个人，那么他的右边是则为第一个人。例如删除编号1，删除后编号2将变成第一人</span></span><br><span class="line">                fristPeople = p.getRightPeole();</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (p == lastPeople) &#123;</span><br><span class="line">                <span class="comment">// 如果新人是最后一个人，删除后圈里面的最后一个人将变成他左边的人。例如删除4，最后一个人就是4的左边编号为3的人</span></span><br><span class="line">                lastPeople = p.getLeftPeople();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 代码走到了这里，说明p既不是第一个人，也不是最后一个人，是处于中间的人</span></span><br><span class="line">            <span class="comment">// 例如要删除编号为3的人，那么3删除后，2的右边是4,4的右边为2</span></span><br><span class="line">            <span class="comment">// 以编号3为例，获取被删除people编号3左边的人编号2</span></span><br><span class="line">            people leftPeople = p.getLeftPeople();</span><br><span class="line">            <span class="comment">// 获取被删除people编号3右边的人编号4</span></span><br><span class="line">            people rightPeole = p.getRightPeole();</span><br><span class="line">            <span class="comment">// 将左边编号2的人的右边的人设置为编号3的人</span></span><br><span class="line">            leftPeople.setRightPeole(rightPeole);</span><br><span class="line">            <span class="comment">// 将编号4的左边的人设置为编号2</span></span><br><span class="line">            rightPeole.setLeftPeople(leftPeople);</span><br><span class="line">        &#125;</span><br><span class="line">        total--;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">TODO:</span> 计算。调用addPeople()和deletePeople()来完成约瑟夫环</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> total     总人数</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> keyNumber 关键数字，报数</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> javafx.scene.shape.Circle:</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@author</span> shanLan misterchou@qq.com</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@date</span> 2019/7/31 1:11</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> circle <span class="title">compar2</span><span class="params">(Integer total, Integer keyNumber)</span> </span>&#123;</span><br><span class="line">        circle circle = <span class="keyword">new</span> circle();</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; total; i++) &#123;</span><br><span class="line">            people people = <span class="keyword">new</span> people(i);</span><br><span class="line">            <span class="comment">// 开始向圈里添加人</span></span><br><span class="line">            circle.addPeople(people);</span><br><span class="line">        &#125;</span><br><span class="line">        Integer count = <span class="number">0</span>;</span><br><span class="line">        people people = circle.getFristPeople();</span><br><span class="line">        <span class="keyword">while</span> (circle.getTotal() &gt; <span class="number">1</span>) &#123;</span><br><span class="line">            <span class="comment">// 每数一个人，计数器加1次</span></span><br><span class="line">            count++;</span><br><span class="line">            <span class="comment">// 如果计数器等于keyNumber，说明这个人应该被淘汰</span></span><br><span class="line">            <span class="keyword">if</span> (count.equals(keyNumber)) &#123;</span><br><span class="line">                count = <span class="number">0</span>;</span><br><span class="line">                circle.deletPeople(people);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 当people的编号不等于keyNumber的时候，应该当前对象的右边对象赋值给people</span></span><br><span class="line">            people = people.getRightPeole();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> circle;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">circle</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">circle</span><span class="params">(<span class="keyword">int</span> total, people fristPeople, people lastPeople)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.total = total;</span><br><span class="line">        <span class="keyword">this</span>.fristPeople = fristPeople;</span><br><span class="line">        <span class="keyword">this</span>.lastPeople = lastPeople;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getTotal</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> total;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setTotal</span><span class="params">(<span class="keyword">int</span> total)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.total = total;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> people <span class="title">getFristPeople</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> fristPeople;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setFristPeople</span><span class="params">(people fristPeople)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.fristPeople = fristPeople;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> people <span class="title">getLastPeople</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> lastPeople;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setLastPeople</span><span class="params">(people lastPeople)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.lastPeople = lastPeople;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</details>

<p>人People代码：</p>
<details><summary>人People代码完整代码</summary>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">people</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Integer id;</span><br><span class="line">    <span class="keyword">private</span> people leftPeople;</span><br><span class="line">    <span class="keyword">private</span> people rightPeole;</span><br><span class="line">    <span class="comment">// set / get 省略</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</details>
主进程Main调用代码：

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> total = <span class="number">10</span>; <span class="comment">//定义要添加的人数</span></span><br><span class="line">    <span class="keyword">int</span> keyNumber = <span class="number">3</span>; <span class="comment">//数到3退出</span></span><br><span class="line">    circle circle = pojo.circle.compar2(total, keyNumber);</span><br><span class="line">    System.out.println( total + <span class="string">"个人围成一圈数数，数到"</span> + keyNumber + <span class="string">"的被淘汰，最后剩下的是第"</span> + circle.getFristPeople().getId() + <span class="string">"个人。"</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="3-使用链表来解题"><a href="#3-使用链表来解题" class="headerlink" title="3. 使用链表来解题"></a>3. 使用链表来解题</h2><p>使用Java集合自带LinkedList来实现，借用LinkedList的Remove()后， 将任何<strong>后续元素</strong>移动到左侧（从其索引中减去一个元素）的特性实现。并且判断的条件是index 是否等于集合的最后一个下标，如果是，则说明本轮循环已经到尾部了，需要重新开始循环计数了，具体思路：</p>
<ol>
<li>创建一个total长度集合，给集合内添加total个数组，从1开始</li>
<li>定义一个下标index，初始值为0 ，它代表需要删除哪个元素</li>
<li>定义一个循环，循环的结束条件是小于keyNumber，也就是循环次数= keyNumber - 1 次</li>
<li>利用 <code>index  == size()  -  1</code> ，判断是不是已经数到了最后一个元素，如果是，则需要归零index，从0开始计数</li>
<li>当跳出循环时，说明此时index符合删除的条件了</li>
<li>使用remove(index)删除元素，该index元素的后续元素位置都会向左移动，并且索引会-1</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">    Integer total = <span class="number">10</span>;</span><br><span class="line">    Integer keyNumber = <span class="number">3</span>;</span><br><span class="line">    <span class="comment">// 创建链表</span></span><br><span class="line">    LinkedList&lt;Integer&gt; list = <span class="keyword">new</span> LinkedList&lt;&gt;();</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; total; i++) &#123;</span><br><span class="line">        <span class="comment">// 给链表里添加编号，从1开始</span></span><br><span class="line">        list.addLast(i + <span class="number">1</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 下标</span></span><br><span class="line">    <span class="keyword">int</span> index = <span class="number">0</span>;</span><br><span class="line">    <span class="comment">// 当链表的长度大于1时</span></span><br><span class="line">    <span class="keyword">while</span> (list.size() &gt; <span class="number">1</span>) &#123;</span><br><span class="line">        <span class="comment">// 循环，限定条件是小于keyNumber，例如keyNumber=3，所以每次循环是3-1次</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; keyNumber; i++) &#123;</span><br><span class="line">            <span class="comment">// 如果下标等于列表长度-1</span></span><br><span class="line">            <span class="keyword">int</span> length = list.size() - <span class="number">1</span>;</span><br><span class="line">            <span class="comment">// 如果下标等于最大长度-1，说明已经数到了最后一个人了，那么就需要从头开始数，也就是归零。因为最后一个人的下标就是size()-1</span></span><br><span class="line">            <span class="keyword">if</span> (index == length) &#123;</span><br><span class="line">                <span class="comment">// 下标归零</span></span><br><span class="line">                index = <span class="number">0</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 防止越界</span></span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> (index == list.size()) &#123;</span><br><span class="line">                index = <span class="number">1</span>;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">// 下标递进</span></span><br><span class="line">                index++;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 删除指定下标；当上面循环结束以后，i &lt; keyNumber跳出循环时，index++的数字正好符合游戏规则，</span></span><br><span class="line">        <span class="comment">// 因为index是随着 i 在进行自增。例如keyNumber = 3，那么index的数字依次是：2,</span></span><br><span class="line">        <span class="comment">// 下一轮按理说是5该删除，但是5这步骤不需要累加index了，直接走到了删除的代码，所以第二轮是删除了下标index= 4的元素</span></span><br><span class="line">        <span class="comment">// 同上，应该累加到7的时候删除元素，但是此时代码跳到了删除元素那样，所以index没有累加，此时index是7</span></span><br><span class="line">        list.remove(index);</span><br><span class="line">    &#125;</span><br><span class="line">    System.out.println(total + <span class="string">"个人围成一圈数数，数到"</span> + keyNumber + <span class="string">"的被淘汰，最后剩下的是第"</span> + list.get(<span class="number">0</span>) + <span class="string">"个人。"</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>参考自：约瑟夫环的几种实现方式 - 菜鸟小站 - OSCHINA - <a href="https://my.oschina.net/jack90john/blog/1791110" target="_blank" rel="noopener">https://my.oschina.net/jack90john/blog/1791110</a></p>
</blockquote>
<h1 id="5-26个字母a-z，找出所有字母的组合，a-b-c-ab-abc-a-z都是一个组合（顺序无关）"><a href="#5-26个字母a-z，找出所有字母的组合，a-b-c-ab-abc-a-z都是一个组合（顺序无关）" class="headerlink" title="5. 26个字母a-z，找出所有字母的组合，a,b,c,ab,abc,a~z都是一个组合（顺序无关）"></a>5. 26个字母a-z，找出所有字母的组合，a,b,c,ab,abc,a~z都是一个组合（顺序无关）</h1><p>待补充</p>

      
    </div>

    <div class="article-footer" name="文章脚部">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="https://blog.gobyte.cn/post/8905a03f.html" title="02-深圳市南山区-同行者科技有限公司面试总结" target="_blank" rel="external">https://blog.gobyte.cn/post/8905a03f.html</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/shanlanCoding" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/images/ha-002-small.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/shanlanCoding" target="_blank"><span class="text-dark">山岚</span><small class="ml-1x">半吊子全栈开发者</small></a></h3>
        <div>大龄萌新；新时代福娃；喜欢东搞西搞；对待问题有独到的见解；</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/post/a316b08b.html" title="03-杜尔涂装系统工程（上海）有限公司ITAC面试总结"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/post/4a74da6f.html" title="01-深圳市罗湖区-中科软面试总结"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  
  <div class="bar-right">
    
  </div>
  </div>
</nav>
  



  	<script>
	  <!-- 百度站长自动推送链接 -->
		(function(){
		var bp = document.createElement('script');
		var curProtocol = window.location.protocol.split(':')[0];
		if (curProtocol === 'https') {
			bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
		}
		else {
			bp.src = 'http://push.zhanzhang.baidu.com/push.js';
		}
		var s = document.getElementsByTagName("script")[0];
		s.parentNode.insertBefore(bp, s);
		})();
	</script>
</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/shanlanCoding" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=CWRgen1se2phZnxJeHgnamZk" target="_blank" title="Email" data-toggle=tooltip data-placement=top><i class="icon icon-email"></i></a></li>
        
    </ul>



	<div class="powered-by" name="不蒜子" sytle="font-size:12px">
		<i class="icon icon-users"></i>
		<span id="busuanzi_container_site_uv">
			总访客 : <span id="busuanzi_value_site_uv"></span>
		</span><br/>
		<i class="icon icon-eye-fill"></i>
		<span id="busuanzi_container_site_pv">
		    总阅读 : <span id="busuanzi_value_site_pv"></span>
		</span>
	</div>
    
	<div class="copyright" name="作者">
		
		<div class="publishby">
			Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
		</div>
	</div>

</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>

<script>
	window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')

		<!-- 百度统计 -script.ejs --> 
		var _hmt = _hmt || [];
		(function() {
		  var hm = document.createElement("script");
		  hm.src = "https://hm.baidu.com/hm.js?e003775b21b75a71e1396c1fc395cce7";
		  var s = document.getElementsByTagName("script")[0]; 
		  s.parentNode.insertBefore(hm, s);
		})();

		<!-- 新浪云防盗链 -->
		var link = "" ;
		setTimeout( function(){
			$("img").each( (i,o) => {
				var o = $(o);
				if(o.attr("src").indexOf("sinaimg") > 0 ){
					o.attr("referrerpolicy","no-referrer");
					link = o.attr("src");
					o.attr("src",link);
				}
			});
		},1000);

</script>

<script src="/js/plugin.min.js"></script>
<script src="/js/application.js"></script>

    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>






	
   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: 'ksrz2lYRLkGCOqMraVC2gBB3-gzGzoHsz',
    appKey: 'ehlbHl0wgN6gbvN4NQexYxnl',
    placeholder: '说点什么吧？',
    avatar: 'robohash',
    meta: meta,
    pageSize: '10' || 10,
    visitor: true
  });
  </script>

     







</body>
</html>